// 1. 引入二次封装的axios
import request from '@/utils/request';
import type { AttrInfoModel, AttrListModel } from './model/attrModel';
import type { CategoryIdsModel } from './model/categoryStoreModel';

// 2. 使用枚举来保存接口
enum Api {
  // 根据三级导航来获取属性列表数据
  getAttrListApi = '/admin/product/attrInfoList',
  // 删除平台属性
  deleteAttrInfoApi = '/admin/product/deleteAttr',
  //添加平台属性或更新平台属性
  saveOrUpdateAttrInfoApi = '/admin/product/saveAttrInfo',
}

// 定义接口函数

// 3. 根据一二三级ID来获取分类列表数据
export const reqGetAttrListData = ({
  category1Id,
  category2Id,
  category3Id,
}: CategoryIdsModel) => {
  return request.get<any, AttrListModel>(
    Api.getAttrListApi + `/${category1Id}/${category2Id}/${category3Id}`
  );
};

// 4. 删除平台属性
/**
 * 定义了一个删除平台属性的接口函数
 * @param attrId
 * @returns
 */
export const reqDeleteAttrInfo = (attrId: number) => {
  return request.delete<any, null>(Api.deleteAttrInfoApi + `/${attrId}`);
};

//5. 添加或者更新平台属性
export const reqSaveOrUpdateAttrInfo = (attrInfo: AttrInfoModel) => {
  return request.post<any, null>(Api.saveOrUpdateAttrInfoApi, attrInfo);
};
